package com.android.rapidcash.viewmodel

import androidx.lifecycle.MutableLiveData
import com.android.lib.base.baseclass.BaseViewModel
import com.android.lib.base.manager.MMKVManager
import com.android.lib.base.network.*
import com.android.rapidcash.api.ApiService
import com.android.rapidcash.bean.*
import com.android.rapidcash.utils.CommUtils
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import okhttp3.MultipartBody

class MainViewModel : BaseViewModel() {

    private val mApiService by lazy { RetrofitClient.getInstance().create(ApiService::class.java) }

    val getVerifCode = MutableLiveData<SmsBean>()
    val loginForSms = MutableLiveData<LoginBean>()

    //不做任何预处理，由下层自行处理
    fun getVerifCode(phoneNo: String) {
        launch {
            val body = getBody()
            body["giftedSpecialistTheftTemple"] = phoneNo
            mApiService.getVerifCode(true, body)
                .bindLoading(this@MainViewModel)
                .asSuccess()
                .collect {
                    getVerifCode.postValue(it)
                }
        }
    }

    //不做任何预处理，由下层自行处理
    fun loginForSms(phoneNo: String, smsCode: String) {
        launch {
            val body = getBody()
            body["giftedSpecialistTheftTemple"] = phoneNo
            body["singleSunRoundaboutArithmetic"] = smsCode//
            body["maximumCuriousAccount"] = "00000000-0000-0000-0000-000000000000"//gaid
            body["federalHugeHarbourSouvenirs"] = "appInstanceId"//appInstanceId
            mApiService.loginForSms(true, body)
                .bindLoading(this@MainViewModel)
                .asSuccess()
                .collect {
                    loginForSms.postValue(it)
                }
        }
    }

    val index = MutableLiveData<IndexBean>()
    fun index() {
        launch {
            val body = getBody()
            mApiService.index(!CommUtils.isLogin(), body)
                .bindLoading(this@MainViewModel)
                .asSuccess()
                .collect {
                    index.postValue(it)
                }
        }
    }

    val custInfoBasicQuery = MutableLiveData<CustInfoBasicQueryBean>()
    fun custInfoBasicQuery() {
        launch {
            val body = getBody()
            mApiService.custInfoBasicQuery(false, body)
                .bindLoading(this@MainViewModel)
                .asSuccess()
                .collect {
                    custInfoBasicQuery.postValue(it)
                }
        }
    }

    val getIdentificationResult = MutableLiveData<GetIdentificationResultBean>()
    fun getIdentificationResult() {
        launch {
            val body = getBody()
            mApiService.getIdentificationResult(false, body)
                .bindLoading(this@MainViewModel)
                .asSuccess()
                .collect {
                    getIdentificationResult.postValue(it)
                }
        }
    }

    val getAppValueList = MutableLiveData<AppValueBean>()
    fun getAppValueList() {
        launch {
            val body = getBody()
            mApiService.getAppValueList(false, body)
                .bindLoading(this@MainViewModel)
                .asSuccess()
                .collect {
                    getAppValueList.postValue(it)
                }
        }
    }

    val vipProducts = MutableLiveData<BannerBean>()
    fun vipProducts() {
        launch {
            val body = getBody()
            mApiService.vipProducts(false, body)
                .bindLoading(this@MainViewModel)
                .asSuccess()
                .collect {
                    vipProducts.postValue(it)
                }
        }
    }


    private fun getBody(): MutableMap<String, String> {
        return mutableMapOf(
            "bestFingernailProbableDialogueHarmlessMainland" to "202",
            "russianGasStrictSteam" to MMKVManager.decodeString("userID"),
            "physicalSpaceshipFeeVastBill" to "0,0",
            "readySleeveAddress" to "es",
        )

    }


}